﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _04_Array类
{
    public enum PersonCompareType
    {
        Id,
        Name
    }
    public class PersonCompare : IComparer<Person>//IComparer利用单独存在的排序类来完成对数组的排序
    {
        private PersonCompareType _comparetype;
        public PersonCompare(PersonCompareType comparetype)
        {
            this._comparetype = comparetype;
        }


        public int Compare(Person x, Person y)
        {
            if (x == null || y == null) throw new ArgumentNullException("Argument Null");
            int result = 0;
            switch (_comparetype)
            {
                case PersonCompareType.Id:
                    result = x.Id.CompareTo(y.Id);
                    break;
                case PersonCompareType.Name:
                    result = x.Name.CompareTo(y.Name);
                    break;
                
            }
            return result;
        }
    }
}
